package org.corey.share.business;

import java.util.Date;

import org.corey.share.db.entity.User;
import org.corey.share.db.service.AuthServiceImpl;
import org.corey.share.db.service.UserService;
import org.corey.share.db.service.UserServiceImpl;
import org.corey.share.throwable.ValidationUserException;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class LoginAction extends ActionSupport {
	public UserService userService = new UserServiceImpl();
	private String userName;
	private String password;
	private String checkCode;
	private String oldPassword;
	private String newPassword;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getCheckCode() {
		return checkCode;
	}

	public void setCheckCode(String checkCode) {
		this.checkCode = checkCode;
	}

	public String getOldPassword() {
		return oldPassword;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	public String getNewPassword() {
		return newPassword;
	}

	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}

	public String execute() throws ValidationUserException {
		boolean isOK = AuthServiceImpl.getInstance().login(userName, password, "");
		if (isOK) {
			return SUCCESS;
		}
		return SUCCESS;
	}

	public String repassword() throws ValidationUserException {
		userService.rePassword(userName, oldPassword, newPassword);
		return SUCCESS;
	}

	public String registeUser() {
		User u = new User();
		u.setUserName(this.getUserName());
		u.setPassword(this.password);
		u.setRegsiterDate(new Date());
		User user = userService.registeUser(u);
		return SUCCESS;
	}

}